package com.eightworld3.supermarket.controller;

import com.eightworld3.supermarket.domain.WarePrice;
import com.eightworld3.supermarket.service.WarePriceService;
import com.eightworld3.supermarket.service.dto.WarePriceDTO;
import com.eightworld3.supermarket.service.dto.add.WarePriceAddDTO;
import com.eightworld3.supermarket.service.dto.result.ResponseResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author EightWorld3
 */
@Tag(name = "WarePriceController",description = "商品价格管理")
@RestController
@RequestMapping("/warePrice")
public class WarePriceController {
    private final WarePriceService warePriceService;


    /**
     * WarePriceController构造方法
     * @param warePriceService 商品价格Service
     */
    public WarePriceController(WarePriceService warePriceService){
        this.warePriceService = warePriceService;
    }

    /**
     * 查询所有
     * @return 返回所有WarePrice(商品价格)
     */
    @Operation(summary = "查询所有商品价格(WarePrice)",description = "查询所有商品价格(WarePrice)")
    @GetMapping("/allWarePrice")
    public List<WarePrice> getAll(){
        return warePriceService.selectAll();
    }

    /**
     * 根据warePriceId查询WarePrice
     * @param warePriceId ID号
     * @return 返回warePriceId对应的WarePrice对象(经ResponseResult包装类修饰)
     */
    @Operation(summary = "根据warePriceId查询商品价格(WarePrice)",description = "根据warePriceId查询商品价格(WarePrice)")
    @GetMapping("/getWarePriceByWarePriceId/{warePriceId}")
    public ResponseResult getWarePriceByWarePriceId(@PathVariable("warePriceId")int warePriceId){
        return warePriceService.selectByWarePriceId(warePriceId);
    }

    /**
     * 新增WarePrice
     * @param warePriceAddDTO WarePrice新增DTO对象
     * @return 返回当前当次新增状况(经ResponseResult包装类修饰)
     */
    @Operation(summary = "新增商品价格(WarePrice)",description = "Test：商品(外键)、商品价格(>0)、商品折扣(0~10)、备注(varchar(120))")
    @PostMapping("/addWarePrice")
    public ResponseResult addWarePrice(@RequestBody WarePriceAddDTO warePriceAddDTO){
        return warePriceService.addWarePrice(warePriceAddDTO);
    }

    /**
     * 更新WarePrice
     * @param warePriceDTO WarePrice DTO对象
     * @return 返回当前当次更新状况(经ResponseResult包装类修饰)
     */
    @Operation(summary = "更新商品价格(WarePrice)",description = "Test：商品(外键)、商品价格(>0)、商品折扣(0~10)、备注(varchar(120))")
    @PutMapping("/updateWarePrice")
    public ResponseResult updateWarePrice(@RequestBody WarePriceDTO warePriceDTO){
        return warePriceService.updateWarePrice(warePriceDTO);
    }

    /**
     * 根据warePriceId删除WarePrice
     * @param warePriceId ID号
     * @return 返回当前当次删除状况(经ResponseResult包装类修饰)
     */
    @Operation(summary = "据warePriceId删除商品价格(WarePrice)",description = "据warePriceId删除商品价格(WarePrice)")
    @DeleteMapping("/deleteWarePriceByWarePriceId/{warePriceId}")
    public ResponseResult deleteWarePriceByWarePriceId(@PathVariable("warePriceId")int warePriceId){
        return warePriceService.deleteWarePriceById(warePriceId);
    }
}
